package com.datasource.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.datasource.constants.DBConstants;
import com.datasource.entity.OrderDO;
import com.datasource.mapper.OrderMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author ytj
 * @date 2021/12/14
 */
@Service
@DS(DBConstants.DATASOURCE_SLAVE)
public class OrderService {
    @Resource
    private OrderMapper orderMapper;

    @Transactional
    @DS(DBConstants.DATASOURCE_MASTER)
    public void add(OrderDO orderDO){
        orderMapper.selectById(orderDO.getId());
        orderMapper.insert(orderDO);
    }

    public OrderDO findById(Integer id){
        return orderMapper.selectById(id);
    }
}
